/**
 * 
 */
package cx3k.GUI;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.*;

/**
 * @author Chris
 *
 */
public class SearchOptionsPane extends JPanel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JButton jbAll, jbRequired;
	private JButton jbSS, jbM, jbWI, jbAH, jbPE, jbLC, jbBPS;
	private JComboBox jcbMajor;
	private JCheckBox jcb1, jcb2, jcb3, jcb4;
	private JCheckBox jcbMon, jcbTues, jcbWed, jcbThurs, jcbFri;
	private Box gfrBox;
	
	public SearchOptionsPane() {
		this.setBackground(MainWindow.MAINCOLOR);
		this.setLayout(new GridLayout(4, 1));
		Box MajorBox = Box.createHorizontalBox();
		gfrBox = Box.createHorizontalBox();
		Box DayBox = Box.createHorizontalBox();
		Box LevelBox = Box.createHorizontalBox();
		MajorListener ML = new MajorListener();
		gfrListener GL = new gfrListener();
		LevelListener LL = new LevelListener();
		DayListener DL = new DayListener();
		
		jbAll = new JButton("All ");
		initalizeButton(jbAll);
		jbAll.addActionListener(ML);
		jbRequired = new JButton(" Required ");
		initalizeButton(jbRequired);
		jbRequired.addActionListener(ML);
		
		jcbMajor = new JComboBox();
		jcbMajor.setCursor(new Cursor(Cursor.HAND_CURSOR));
		jcbMajor.addItemListener(ML);
		jcbMajor.addItem("");
		jcbMajor.addItem("CMSC");
		jcbMajor.addItem("IS");
		
		MajorBox.add(jbAll);
		MajorBox.add(new JLabel(" | "));
		MajorBox.add(jbRequired);
		MajorBox.add(new JLabel(" | "));
		MajorBox.add(new JLabel("  Major:   "));
		MajorBox.add(jcbMajor);
		MajorBox.add(Box.createHorizontalGlue());
		this.add(MajorBox);
		
		jcb1 = new JCheckBox();
		initalizeCheckBox(jcb1);
		jcb1.addActionListener(LL);
		jcb2 = new JCheckBox();
		initalizeCheckBox(jcb2);
		jcb2.addActionListener(LL);
		jcb3 = new JCheckBox();
		initalizeCheckBox(jcb3);
		jcb3.addActionListener(LL);
		jcb4 = new JCheckBox();
		initalizeCheckBox(jcb4);
		jcb4.addActionListener(LL);
		
		LevelBox.add(new JLabel("Level: "));
		LevelBox.add(jcb1);
		LevelBox.add(new JLabel("100 "));
		LevelBox.add(jcb2);
		LevelBox.add(new JLabel("200 "));
		LevelBox.add(jcb3);
		LevelBox.add(new JLabel("300 "));
		LevelBox.add(jcb4);
		LevelBox.add(new JLabel("400"));
		this.add(LevelBox);
		
		jbSS = new JButton("SS ");
		initalizeButton(jbSS);
		jbSS.addActionListener(GL);
		jbM  = new JButton(" M ");
		initalizeButton(jbM);
		jbM.addActionListener(GL);
		jbWI = new JButton(" WI ");
		initalizeButton(jbWI);
		jbWI.addActionListener(GL);
		jbAH = new JButton(" AH ");
		initalizeButton(jbAH);
		jbAH.addActionListener(GL);
		jbPE = new JButton(" PE ");
		initalizeButton(jbPE);
		jbPE.addActionListener(GL);
		jbLC = new JButton(" L/C ");
		initalizeButton(jbLC);
		jbLC.addActionListener(GL);
		jbBPS = new JButton(" B/PS");
		initalizeButton(jbBPS);
		jbBPS.addActionListener(GL);
		
		gfrBox.add(jbSS);
		gfrBox.add(new JLabel(" | "));
		gfrBox.add(jbM);
		gfrBox.add(new JLabel(" | "));
		gfrBox.add(jbWI);
		gfrBox.add(new JLabel(" | "));
		gfrBox.add(jbAH);
		gfrBox.add(new JLabel(" | "));
		gfrBox.add(jbPE);
		gfrBox.add(new JLabel(" | "));
		gfrBox.add(jbLC);
		gfrBox.add(new JLabel(" | "));
		gfrBox.add(jbBPS);
		this.add(gfrBox);
		
		jcbMon = new JCheckBox();
		initalizeCheckBox(jcbMon);
		jcbMon.addActionListener(DL);
		jcbTues = new JCheckBox();
		initalizeCheckBox(jcbTues);
		jcbTues.addActionListener(DL);
		jcbWed = new JCheckBox();
		initalizeCheckBox(jcbWed);
		jcbWed.addActionListener(DL);
		jcbThurs = new JCheckBox();
		initalizeCheckBox(jcbThurs);
		jcbThurs.addActionListener(DL);
		jcbFri = new JCheckBox();
		initalizeCheckBox(jcbFri);
		jcbFri.addActionListener(DL);
		
		JLabel jlMon = new JLabel(" M  ");
		JLabel jlTues = new JLabel(" Tu  ");
		JLabel jlWed = new JLabel(" W  ");
		JLabel jlThurs = new JLabel(" Th  ");
		JLabel jlFri = new JLabel(" F");
		
		DayBox.add(jcbMon);
		DayBox.add(jlMon);
		DayBox.add(jcbTues);
		DayBox.add(jlTues);
		DayBox.add(jcbWed);
		DayBox.add(jlWed);
		DayBox.add(jcbThurs);
		DayBox.add(jlThurs);
		DayBox.add(jcbFri);
		DayBox.add(jlFri);
		this.add(DayBox);
		
	}
	
	private void initalizeButton(JButton b) {
		b.setBackground(MainWindow.MAINCOLOR);
		b.setBorder(null);
		b.setCursor(new Cursor(Cursor.HAND_CURSOR));
	}
	
	private void initalizeCheckBox(JCheckBox cb) {
		cb.setBackground(MainWindow.MAINCOLOR);
		cb.doClick();
		cb.setCursor(new Cursor(Cursor.HAND_CURSOR));
	}
	
	private class MajorListener implements ActionListener, ItemListener {

		@Override
		public void actionPerformed(ActionEvent ae) {
			// TODO Auto-generated method stub
			if (ae.getSource() == jbAll) {
				if (jbAll.getForeground() != Color.RED) {
					jcbMajor.setSelectedIndex(0);
					jbAll.setForeground(Color.RED);
					jbRequired.setForeground(Color.black);
				}
				else {
					jbAll.setForeground(Color.BLACK);
				}
			}
			else if (ae.getSource() == jbRequired) {
				if (jbRequired.getForeground() != Color.RED) {
					jcbMajor.setSelectedIndex(0);
					jbAll.setForeground(Color.black);
					jbRequired.setForeground(Color.RED);
				}
				else {
					jbRequired.setForeground(Color.BLACK);
				}
			}
		}

		@Override
		public void itemStateChanged(ItemEvent ie) {
			// TODO Auto-generated method stub
			if (ie.getSource() == jcbMajor) {
				jbAll.setForeground(Color.black);
				jbRequired.setForeground(Color.black);
			}
		}
		
	}
	
	private class LevelListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent ae) {
			// TODO Auto-generated method stub
			if (ae.getSource() == jcb1) {
				
			}
			else if (ae.getSource() == jcb2) {
				
			}
			else if (ae.getSource() == jcb3) {
				
			}
			else if (ae.getSource() == jcb4) {
	
			}
		}
		
	}
	
	private class gfrListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent ae) {
			// TODO Auto-generated method stub
			if (ae.getSource() == jbSS) {
				if (jbSS.getForeground() != Color.RED) {
					for (int i = 0; i < gfrBox.getComponentCount(); i++) {
						gfrBox.getComponent(i).setForeground(Color.black);
					}
					jbSS.setForeground(Color.RED);
				}
				else {
					jbSS.setForeground(Color.black);
				}
			}
			else if (ae.getSource() == jbM) {
				if (jbM.getForeground() != Color.RED) {
					for (int i = 0; i < gfrBox.getComponentCount(); i++) {
						gfrBox.getComponent(i).setForeground(Color.black);
					}
					jbM.setForeground(Color.RED);
				}
				else {
					jbM.setForeground(Color.black);
				}
			}
			else if (ae.getSource() == jbWI) {
				if (jbWI.getForeground() != Color.RED) {
					for (int i = 0; i < gfrBox.getComponentCount(); i++) {
						gfrBox.getComponent(i).setForeground(Color.black);
					}
					jbWI.setForeground(Color.RED);
				}
				else {
					jbWI.setForeground(Color.black);
				}
			}
			else if (ae.getSource() == jbAH) {
				if (jbAH.getForeground() != Color.RED) {
					for (int i = 0; i < gfrBox.getComponentCount(); i++) {
						gfrBox.getComponent(i).setForeground(Color.black);
					}
					jbAH.setForeground(Color.RED);
				}
				else {
					jbAH.setForeground(Color.black);
				}
			}
			else if (ae.getSource() == jbPE) {
				if (jbPE.getForeground() != Color.RED) {
					for (int i = 0; i < gfrBox.getComponentCount(); i++) {
						gfrBox.getComponent(i).setForeground(Color.black);
					}
					jbPE.setForeground(Color.RED);
				}
				else {
					jbPE.setForeground(Color.black);
				}
			}
			else if (ae.getSource() == jbLC) {
				if (jbLC.getForeground() != Color.RED) {
					for (int i = 0; i < gfrBox.getComponentCount(); i++) {
						gfrBox.getComponent(i).setForeground(Color.black);
					}
					jbLC.setForeground(Color.RED);
				}
				else {
					jbLC.setForeground(Color.black);
				}
			}
			else if (ae.getSource() == jbBPS) {
				if (jbBPS.getForeground() != Color.RED) {
					for (int i = 0; i < gfrBox.getComponentCount(); i++) {
						gfrBox.getComponent(i).setForeground(Color.black);
					}
					jbBPS.setForeground(Color.RED);
				}
				else {
					jbBPS.setForeground(Color.black);
				}
			}
		}
		
	}
	
	private class DayListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent ae) {
			// TODO Auto-generated method stub
			if (ae.getSource() == jcbMon) {
				
			}
			else if (ae.getSource() == jcbTues) {
				
			}
			else if (ae.getSource() == jcbWed) {
				
			}
			else if (ae.getSource() == jcbThurs) {
	
			}
			else if (ae.getSource() == jcbFri) {
				
			}
		}
		
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
